package com.pay.service;

import com.pay.dao.AppMapper;
import com.pay.dao.OrderMapper;
import com.pay.model.App;
import com.pay.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by chenweiyi on 2018/1/30.
 */
@Service("payService")
public class PayServiceImpl implements  PayService {

    @Autowired
    private AppMapper appMapper;

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public Map<String, Object> findUserById(String id) {

        return appMapper.findUserById(id);
    }

    @Override
    public App findAppByAppid(String appid) {
        return appMapper.findAppByAppid(appid);
    }

    @Override
    public Order findOrderByOrderNo(String orderNo) {

        return orderMapper.findOrderByOrderNo(orderNo);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int insertOrder(Order order) {

        return orderMapper.insertSelective(order);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int updateOrder(Order order) {
        return orderMapper.updateSelective(order);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int updateProfit(App app) {
        return appMapper.updateProfit(app);
    }

    @Override
    public App findAppByPrimaryKey(Integer id) {
        return appMapper.findAppByPrimaryKey(id);
    }
}
